//
//  WCZixunViewController.swift
//  iiatn
//
//  Created by mnine on 18/3/30.
//  Copyright © 2018年 mnine. All rights reserved.
//

import UIKit
import SVProgressHUD

let zixunCellID = "zixunCellID"
class WCZixunViewController: UITableViewController {

    /// 首页列表数据
    var items = [WZiXun]()
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.automaticallyAdjustsScrollViewInsets = false
        view.backgroundColor = WGlobalWhiteColor()
        
        setupTableView()
        // 添加刷新控件
        refreshControl?.addTarget(self, action: #selector(loadData), for: .valueChanged)
        // 被继承的东西－－－－
    }
    
    func loadData() {
        // 被继承需加载－－－－
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    func setupTableView() {
        
        view.backgroundColor = WLightWhiteColor()
        
        SVProgressHUD.showProgress(0.5)
        tableView.rowHeight = 140
        tableView.separatorStyle = .singleLineEtched
        // top left bottom right
        tableView.contentInset = UIEdgeInsetsMake(kTitlesViewY, 0, 0, 0)
        tableView.scrollIndicatorInsets = tableView.contentInset
        /// 切入视图cell，并注册
        let nib = UINib(nibName: String(describing: WZixunViewCell.self), bundle: nil)
        tableView.register(nib, forCellReuseIdentifier: zixunCellID)
    }
    
    // MARK: - Table view data source
    
    // 多少组数据
    override func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    
    // 一共多少行
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return items.count
    }
    
    // 行数据定义
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let zxcell = tableView.dequeueReusableCell(withIdentifier: zixunCellID) as! WZixunViewCell
        zxcell.selectionStyle = .gray
        zxcell.zixunItem = items[indexPath.row]
        
        return zxcell
    }
    
    // MARK: - UITableViewDelegate
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let detailVC = WZixunDetailViewController()
        detailVC.zixunItem = items[indexPath.row]
        detailVC.title = " "
        navigationController?.pushViewController(detailVC, animated: true)
    }

}
